/**
 * @program: LeetCode
 * @ClassName Num039
 * @description: LeetCode :剑指 Offer 39. 数组中出现次数超过一半的数字
 * @author: WXY
 * @create: 2022-12-09 16:47
 * @Version 1.0
 **/


public class Num039_majorityElement {
    public int majorityElement(int[] nums) {
        int N =  0;
        int count = 0;
        for (int i = 0; i < nums.length; i++) {
            if (count == 0) {
                N = nums[i];
            }
            if (N == nums[i]) {
                count++;
            } else {
                count--;
            }
        }
        return N;
    }
}
